home *** CD-ROM | disk | FTP | other *** search
/ Aminet 31 / Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso / Aminet / dev / gui / gtlayout.lha / Source / LTP_CheckGlyph.c < prev    next >
C/C++ Source or Header  |  1998-09-09  |  3KB  |  153 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1998 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. /*****************************************************************************/
  15.  
  16. #include <exec/memory.h>
  17.  
  18. /*****************************************************************************/
  19.  
  20. #include "Assert.h"
  21.  
  22. #define VECTOR_BYTES(n)    (((n) * 5 + 1) & ~1)
  23.  
  24. VOID
  25. LTP_DrawCheckGlyph(struct RastPort *RPort,LONG Left,LONG Top,struct CheckGlyph *Glyph,BOOL Selected)
  26. {
  27.     struct BitMap *BitMap;
  28.  
  29.     if(Selected)
  30.         BitMap = Glyph->Selected;
  31.     else
  32.         BitMap = Glyph->Plain;
  33.  
  34.     BltBitMapRastPort(BitMap,0,0,RPort,Left,Top,Glyph->Width,Glyph->Height,0xC0);
  35. }
  36.  
  37. VOID
  38. LTP_DeleteCheckGlyph(struct CheckGlyph *Glyph)
  39. {
  40.     if(Glyph)
  41.     {
  42.         WaitBlit();
  43.  
  44.         LTP_DeleteBitMap(Glyph->Plain,FALSE);
  45.         LTP_DeleteBitMap(Glyph->Selected,FALSE);
  46.  
  47.         FreeVec(Glyph);
  48.     }
  49. }
  50.  
  51. struct CheckGlyph *
  52. LTP_CreateCheckGlyph(LONG Width,LONG Height,struct BitMap *Friend,LONG BackPen,LONG GlyphPen)
  53. {
  54.     struct CheckGlyph *Glyph;
  55.     struct RastPort *RPort;
  56.  
  57.     Glyph = NULL;
  58.  
  59.     if(RPort = (struct RastPort *)AllocVec(sizeof(struct RastPort) + sizeof(struct TmpRas) + sizeof(struct AreaInfo) + VECTOR_BYTES(11),MEMF_ANY | MEMF_CLEAR))
  60.     {
  61.         PLANEPTR Plane;
  62.  
  63.         if(Plane = AllocRaster(Width,Height))
  64.         {
  65.             struct BitMap *BitMaps[2] = { NULL, NULL };    /* For the sake of the compiler, make sure this is initialized */
  66.             LONG i,Depth,Max;
  67.  
  68.             Depth = 8;    /* For the sake of the compiler, make sure this is initialized */
  69.  
  70.             if(BackPen > GlyphPen)
  71.                 Max = BackPen;
  72.             else
  73.                 Max = GlyphPen;
  74.  
  75.             for(i = 1 ; i <= 8 ; i++)
  76.             {
  77.                 if((1 << i) > Max)
  78.                 {
  79.                     Depth = i;
  80.                     break;
  81.                 }
  82.             }
  83.  
  84.             for(i = 0 ; i < 2 ; i++)
  85.                 BitMaps[i] = LTP_CreateBitMap(Width,Height,Depth,Friend,FALSE);
  86.  
  87.             if(BitMaps[0] && BitMaps[1])
  88.             {
  89.                 if(Glyph = (struct CheckGlyph *)AllocVec(sizeof(struct CheckGlyph),MEMF_ANY | MEMF_CLEAR))
  90.                 {
  91.                     struct TmpRas    *TmpRas;
  92.                     struct AreaInfo    *AreaInfo;
  93.                     LONG             j;
  94.                     LONG             RadiusX,
  95.                                      RadiusY;
  96.  
  97.                     TmpRas        = (struct TmpRas *)(RPort + 1);
  98.                     AreaInfo    = (struct AreaInfo *)(TmpRas + 1);
  99.  
  100.                     Glyph->Width    = Width;
  101.                     Glyph->Height    = Height;
  102.                     Glyph->Plain    = BitMaps[0];
  103.                     Glyph->Selected    = BitMaps[1];
  104.  
  105.                     InitTmpRas(TmpRas,Plane,RASSIZE(Width,Height));
  106.                     InitArea(AreaInfo,(UBYTE *)(AreaInfo + 1),11);
  107.  
  108.                     InitRastPort(RPort);
  109.  
  110.                     RPort->TmpRas    = TmpRas;
  111.                     RPort->AreaInfo    = AreaInfo;
  112.  
  113.                     RadiusX = Width / 4;
  114.                     RadiusY = Height / 4;
  115.  
  116.                     for(j = 0 ; j < 2 ; j++)
  117.                     {
  118.                         RPort->BitMap = BitMaps[j];
  119.  
  120.                         if(j)
  121.                         {
  122.                             SetRast(RPort,BackPen);
  123.                             SetAPen(RPort,GlyphPen);
  124.                         }
  125.                         else
  126.                         {
  127.                             SetRast(RPort,GlyphPen);
  128.                             SetAPen(RPort,BackPen);
  129.                         }
  130.  
  131.                         AreaEllipse(RPort,Width / 2,Height / 2,RadiusX,RadiusY);
  132.                         AreaEnd(RPort);
  133.                     }
  134.                 }
  135.             }
  136.  
  137.             WaitBlit();
  138.  
  139.             if(!Glyph)
  140.             {
  141.                 LTP_DeleteBitMap(BitMaps[0],FALSE);
  142.                 LTP_DeleteBitMap(BitMaps[1],FALSE);
  143.             }
  144.  
  145.             FreeRaster(Plane,Width,Height);
  146.         }
  147.  
  148.         FreeVec(RPort);
  149.     }
  150.  
  151.     return(Glyph);
  152. }
  153.